//不同于lodash的set，有复杂的类型判断，这里只用作简单的object的多级别访问
import {isNumberString} from'./isNumberString';
//a.b.1.2
export const simpleSet=(obj,path,val)=>{
    if(typeof path==='string'){
        path=path.split('.')
    }
    let now=obj;
    let prev=obj;
    let key;
    for(let i=0;i<path.length-1;i++){
        key=path[i];
        prev=now;
        now=now[key];
        if(now===null||now===undefined||(
            typeof now!=='object'
        )){
            prev[key]=isNumberString(key)?[]:{};
            now=prev[key];
        }
    }
    now[path[path.length-1]]=val;
};
export default simpleSet;